//% color="#ef784c" iconWidth=50 iconHeight=40
namespace QianfanChat{

    //% block="初始化百度千帆模型,API_KEY:[APIKEY],SECRET_KEY[SECRET]" blockType="command"
    //% APIKEY.shadow="string" APIKEY.defl=" "
    //% SECRET.shadow="string" SECRET.defl=" "
    export function readcap(parameter: any, block: any) {
        let key=parameter.APIKEY.code;
        let sceret_key=parameter.SECRET.code;
        Generator.addImport(`import requests\nfrom qianfan_token import get_qianfan_access_token`)
        Generator.addCode(`QIANFAN_APIKEY = ${key}`)
        Generator.addCode(`QIANFAN_SECRETKEY = ${sceret_key}`)
        Generator.addCode(`QIANFAN_TOKEN = get_qianfan_access_token(QIANFAN_APIKEY, QIANFAN_SECRETKEY)`)
    }

    //% block="回答[NAME],限[NUM]字以内" blockType="reporter"
    //% NAME.shadow="string" NAME.defl="你好"
    //% NUM.shadow="number" NUM.defl="30"
    export function takephotoandsave(parameter: any, block: any) {
        let name=parameter.NAME.code;
        let num=parameter.NUM.code;
        Generator.addImport(`from qianfan_handle import qianfan_chat`)
        Generator.addCode(`qianfan_chat(QIANFAN_TOKEN, ${name}, length=${num})`)
	}
